package com.xpgk.mvc.statistic.turnoverRatioJdrStatistic;

import java.util.Date;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.statistic.turnoverRatioStoreStatistic.TurnoverRatioStoreStatisticXLS;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolDateTime;

public class TurnoverRatioJdrStatisticController  extends  BaseController{
	
	private  TurnoverRatioJdrStatisticServices  turnoverRatioJdrStatisticServices;
	
	public  void  index()
	{	
		Organization organ=Organization.dao.findById(getCUserOrganIds());
		setAttr("organization", organ);
		setAttr("startTime", ToolDateTime.getMonthOneDay(new Date()));
		render("turnoverRatioJdrStatistic.html");
	}
	/**获取成交率
	 * 
	 */
	public  void  getTurnoverRatioJdr()
	{	
		String  startTime=getPara("startTime");
		String  endTime=getPara("endTime");
		String  organIds=getPara("organIds");
		List<Record> result=turnoverRatioJdrStatisticServices.getTurnoverRatioJdr(startTime,endTime,organIds,Code.cjCus_ids);
		renderJson(result);
	}
	/**获取未成交率占比
	 * 
	 */
	public  void  getReasonRatio()
	{	
		String  startTime=getPara("startTime");
		String  endTime=getPara("endTime");
		String jdrids = getPara("jdrids");
		String organIds = getPara("organIds");
		String date = getPara("date");
		List<Record> result=turnoverRatioJdrStatisticServices.getReasonRatio(startTime,endTime,date,jdrids,organIds);
		renderJson(result);
	}
	
	public  void  excel()
	{
		String  startTime=getPara("startTime");
		String  endTime=getPara("endTime");
		String  organIds=getPara("organIds");
		
		List<Record> result=turnoverRatioJdrStatisticServices.getTurnoverRatioJdr(startTime,endTime,organIds,Code.cjCus_ids);
//		
//		
		List<Record> recordList=turnoverRatioJdrStatisticServices.excel(startTime,endTime,result,organIds);
//			
		//搜索条件
		Organization  organ=Organization.dao.findById(organIds);
		String  search="日期："+startTime+"~"+endTime+"，门店："+organ.getStr(Organization.column_name)+"，导出人员："+getCUser().getStr(User.column_name);
		render(new TurnoverRatioJdrStatisticXLS(recordList,search,"顾客成交率（接待人）查询表"));
	}
	
	/**弹出成交率（接待人）明细
	 * 
	 */
	public  void  tolookReasonInfo()
	{
		String jdrids=getPara("jdrids");
		String organIds=getPara("organIds");
		String startTime=getPara("startTime");
		String endTime=getPara("endTime");
		setAttr("jdr", User.dao.findById(jdrids));
		setAttr("organ", Organization.dao.findById(organIds));
		setAttr("startTime", startTime);
		setAttr("endTime", endTime);
		render("jdrStatisticInfo.html");
	}
	public void  lookReasonInfo()
	{
		String jdrids=getPara("jdrids");
		String organIds=getPara("organIds");
		String startTime=getPara("startTime");
		String endTime=getPara("endTime");
		List<Record>  result=turnoverRatioJdrStatisticServices.lookReasonInfo(jdrids,organIds,startTime,endTime,Code.cjCus_ids);
		renderJson(result);
	}
	
}
